import storage from '@/utils/storage'

export function createRouterGuards(router) {
  router.beforeEach((to, from) => {
    const Loading = window['$loading'] || null
    Loading && Loading.start()

    // 没有token时跳转登录
    const token = storage.get('token')
    if (to.name !== 'Login' && !token) {
      return { name: 'Login' }
    }
  })
  router.afterEach(() => {
    const Loading = window['$loading'] || null
    setTimeout(() => {
      Loading && Loading.finish()
    }, 500)
  })
}

